import axios from 'axios'

//官网首页api
function home($this){
    axios({
        url: "/offcial/index.php/index/Acticle/pcIndex",
        method: "post",
        data: {}
      })
    .then(function(res) {
        if (res.data.code == 1) {
        $this.data = res.data.data;
        $this.logoPic=res.data.data.logo.img;
        $this.loading.close();
        }else{
            alert(res.data.message)
        }
    })
    .catch(function(res) {});
}
//商品分类api
 function getGoodsList($this){
    var time = Date.parse(new Date())/1000;
    axios({
        url:'/super/api/Shop/categoryList',
        method:'post',
        data:{
            time:time,
            device_id:1532658064,
            version:'1.0.1',
            platform:'h5'
        }
    })
    .then(function(res) {
        if (res.data.code == 1) {
            var data1 = res.data.data;
            var id=res.data.data.list[0].id;
            $this.data1=data1;
            $this.id=id;
            $this.getGoods($this.id,$this.page);
        }else{
            alert(res.data.message)
        }
    })
    .catch(function(res) {});
}
//商品列表api
function getGoods($this,id,page){

    var time = Date.parse(new Date())/1000;
    axios({
    url: "/super/api/Shop/getGoodsByCid",
    method: "post",
    data: {
        time:time,
        device_id:1532658064,
        version:'1.0.1',
        platform:'h5',
        category_id:id,
        page:page,
    }
    })
    .then(function(res) {
    if (res.data.code == 1) {
        $this.data3 = res.data.data;
    }else{
        alert(res.data.message)
    }
    })
    .catch(function(res) {
        
    });
}
//文章分类api
function getActicleList($this){
    var time = Date.parse(new Date())/1000;
    axios({
      url: "/super/api/home/index",
      method: "post",
      data: {
          time:time,
          device_id:1532658064,
          version:'1.0.1',
          platform:'pc'
      }
    })
    .then(function(res) {
    if (res.data.code == 1) {
        $this.data1 = res.data.data;
        $this.category_id=res.data.data.list[0].category_id;
        $this.getActicle($this.category_id,$this.page);
    }else{
        alert(res.data.message)
    }
    })
    .catch(function(res) {
        
    });
};
//文章列表api
function getActicle($this,id,page){
    var time = Date.parse(new Date())/1000;
    axios({
    url: "/super/api/home/getActicle",
    method: "post",
    data: {
        time:time,
        device_id:1532658064,
        version:'1.0.1',
        platform:'pc',
        category_id:id,
        page:page,
    }
    })
    .then(function(res) {
    if (res.data.code == 1) {
        $this.data2 = res.data.data;
    }else{
        alert(res.data.message)
    }
    })
    .catch(function(res) {
        
    });
}
//发展史
function napinDevelop($this){
    axios({
        url: "/offcial/index.php/index/Acticle/Development",
        method: "post",
      })
      .then(function(res) {
      if (res.data.code == 1) {
          $this.develoption=res.data.data;
      }else{
        alert(res.data.message)
    }
      })
      .catch(function(res) {
          
      });
}
//招聘api
function getPcRecruit($this,page,type_id){
    axios({
        url: "/offcial/index.php/index/Acticle/PcRecruit",
        method: "post",
        data:{
            page:page,
            type_id:type_id,
        }
      })
      .then(function(res) {
      if (res.data.code == 1) {
          $this.recruit=res.data.data;
          res.data.data.content.forEach(element => {
              $this.isShow.push(false)
          });
          $this.page_count=res.data.page_count
      }else{
          alert(res.data.message);
          $this.page=1;
      }
      })
      .catch(function(res) {
          
      });
}
//公司环境图片api
function getCompanyEnvironment($this,recruit_id){
    axios({
        url: "/offcial/index.php/index/Acticle/CompanyEnvironment",
        method: "post",
        data:{
            recruit_id:recruit_id
        }
      })
      .then(function(res) {
      if (res.data.code == 1) {
          $this.environment=res.data.data[0];
      }else{
          alert(res.data.message)
      }
      })
      .catch(function(res) {
          
      });
} 
//联系我们api
function GetContact($this){
    axios({
    url: '/offcial/index.php/index/Acticle/GetContact',
    method: 'post',
  })
    .then(function (response) {
      const resData = response.data
      if (resData.code == 1) {
        $this.way = resData.data
      }else{
        alert(res.data.message)
      }
    })
    .catch(function (response) {
      console.log(response)
    })
}
//版本号api
function getVersion($this){
    var time = Date.parse(new Date())/1000;
    axios({
        url: '/super/api/shop/getVersion',
        method: 'post',
        data:{
            time:time,
            device_id:1532658064,
            version:'1.0',
            platform:'pc',
        }
      })
        .then(function (response) {
          const resData = response.data
          if (resData.code == 1) {
            $this.version=response.data.data.url;
          }else{
            alert(res.data.message)
          }
        })
        .catch(function (response) {
          console.log(response)
        })
}
//seoapi
function getSeo($this){
    var time = Date.parse(new Date())/1000;
    axios({
        url: '/offcial/index.php/index/Acticle/seo',
        method: 'post',
      })
        .then(function (response) {
            console.log(response)
          if (response.data.code == 1) {
            var meta=document.getElementsByTagName('meta');
            console.log(11,meta)
            for(var i=0;i<meta.length;i++){
                if(meta[i].getAttribute('name')=='keywords'){
                    console.log(1,meta[i]);
                    meta[i].setAttribute('content',response.data.data.keyword);
                }
                if(meta[i].getAttribute('name')=='description'){
                    meta[i].setAttribute('content',response.data.data.desc);
                }
                // document.getElementsByTagName('title')[0].innerText=response.data.data.title
            }
          }else{
            alert(res.data.message)
          }
        })
        .catch(function (response) {
          console.log(response)
        })
}


export default {home,getGoodsList,getGoods,getActicleList,getActicle,napinDevelop,getPcRecruit,getCompanyEnvironment,GetContact,getVersion,getSeo};